package practice;

public class 定义方法遍历数组 {
    public static void main(String[] args) {
        int a[] = {1,5,4,51,15,4,512,154,4};
        PrintAll(a);
        max(a);
        System.out.println(search(a,3));
        System.out.println(search(a,5));
    }
    public static void PrintAll(int a[]){
        System.out.println(a.length);
        System.out.print("[");
        for(int i=0;i<a.length;i++){
            if(i==a.length-1){
                System.out.print(a[i]);
            }else{
                System.out.print(a[i]+",");
            }
        }
        System.out.println("]");
    }
    public static void max(int a[]){
        int max = a[0];
        for(int i=1;i<a.length;i++){
            if(a[i]>max){
                max=a[i];
            }
        }
        System.out.println(max);
    }
    public static boolean search(int a[],int num){
        for(int i=0;i<a.length;i++){
            if(a[i] == num){
                return true;
            }
        }
        return false;
    }
}
